// Shared functions for drawing
//
// NOTE: internal used, user for application don't need to include this file!

#ifndef __DRAW_SHARED_H__
#define __DRAW_SHARED_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "Color.h"

#define  FLOAT  int         // !!! replace float with integer for speed-up
                            // but may cause overflow
                            // check g_LineClipping, g_DrawCircle, g_FillCircle

// #define DRAW_PIXEL_NC(x,y,c) g_DrawPixelNC(canvas,x,y,c)

#ifndef  DRAW_PIXEL_NC
// Need direct frame buffer accessing support
#define  DIRECT_BUFFER_ACCESS
#endif

// Get frame buffer data macro
#define  FRAME_STRIDE		(canvas->BytesPerRow)
#define  FRAME_ANCHOR(x,y)	(canvas->pData + (y) * FRAME_STRIDE + PIXEL_TO_BYTE(x))

// Set buffer to a specified color
//	dst		destination address
//	colors	color bits of pixel, NOTE: should bind 2 color bits when in __RGB16!
//	count	how many pixels
void memset_color(UInt8 *dst, UInt32 colors, int count);

// Darken is RGBnew = RGBsrc / 2 + RGBdst / 2, i.e. blend(50, 50)
//	dst		destination address
//	colors	color bits of pixel, NOTE: should bind 2 color bits when in __RGB16!
//	count	how many pixels
void memset_darken(UInt8 *dst, UInt32 colors, int count);
//  src		source address
void memcpy_darken(UInt8 *dst, const UInt8 *src, int count);

// Blend is RGBnew = RGBsrc * sf/100 + RGBdst * df/100
//	dst		destination address
//	color	color bits of pixel
//	count	how many pixels
//	sf		source factor, 0 ~ 100
//	df		destination factor, 0 ~ 100
void memset_blend(UInt8 *dst, UInt32 color, int count, int sf, int df);
//  src		source address
void memcpy_blend(UInt8 *dst, const UInt8 *src, int count, int sf, int df);

// Alpha is  RGBnew = RGBsrc * alpha/255 + RGBdst * (255-alpha)/255
//	dst		destination address
//	color	color bits of pixel
//	count	how many pixels
//  alpha	alpha value, 0 ~ 255
void memset_alpha(UInt8 *dst, UInt32 color, int count, UInt8 alpha);
//  src		source address
void memcpy_alpha(UInt8 *dst, const UInt8 *src, int count,  UInt8 alpha);
//	alpha	alpha values of each pixel corresponding in src
void memcpy_alpha_array(UInt8 *dst, const UInt8 *src, int count, const UInt8 *alpha);

void write_pixel_alpha(UInt8 *dst, UInt32 color, UInt8 alpha);

#ifdef __cplusplus
}
#endif

#endif	// __DRAW_SHARED_H__
